import dxui from '../../../dxmodules/dxUi.js'
const pinyin = {}

// Keyboard size
let width = 800
let height = 400
// Lock the keyboard?
let isLock = false
// Does it support Pinyin input?
let enablePinyin = true
// Initialize container
pinyin.init = function (w, h) {
    width = w
    height = h

    // Initialization is allowed only once.
    if (pinyin.inited) {
        return
    }
    pinyin.inited = true
    // Global font
    pinyin.font24 = dxui.Font.build('/app/code/resource/font/AlibabaPuHuiTi-2-65-Medium.ttf', 24, dxui.Utils.FONT_STYLE.NORMAL)
    let container = dxui.View.build('container', dxui.Utils.LAYER.TOP)
    pinyin.container = container
    clearStyle(container)
    container.obj.lvObjAddFlag(dxui.Utils.ENUM.LV_OBJ_FLAG_OVERFLOW_VISIBLE)
    container.setSize(width, height)
    container.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, 0)
    container.textFont(pinyin.font24)
    // Container initialization
    container.bgOpa(0)
    container.update()
    container.hide()
    // Create three keyboard modes
    pinyin.englishPanel = createEnglish()
    pinyin.numPanel = createNum()
    pinyin.symbolPanel = createSymbol()
}
pinyin.getSize = function () {
    return { width: width, height: height }
}
/**
 * To display the keyboard, initialization is required first.
 * @param {number} mode Keyboard modes: 0: English keyboard, 1: Pinyin keyboard, 2: Numeric keypad, 3: Symbol keyboard
 * @param {function} cb Key content callback
 */
pinyin.show = function (mode, cb) {
    if (![0, 1, 2, 3].includes(mode)) {
        return
    }
    this.unlock()
    this.hide()
    // Key content callback
    pinyin.cb = cb
    pinyin.container.show()
    pinyin.container.moveForeground()
    switch (mode) {
        case 0:
            pinyin.englishPanel.show()
            break;
        case 1:
            pinyin.pinyinPanel.show()
            break;
        case 2:
            pinyin.numPanel.show()
            break;
        case 3:
            pinyin.symbolPanel.show()
            break;
        default:
            break;
    }
}
// Get current keyboard mode
pinyin.getMode = function () {
    if (!pinyin.englishPanel.isHide()) {
        return 0
    } else if (!pinyin.pinyinPanel.isHide()) {
        return 1
    } else if (!pinyin.numPanel.isHide()) {
        return 2
    } else if (!pinyin.symbolPanel.isHide()) {
        return 3
    } else {
        return 0
    }
}
// Hide keyboard
pinyin.hide = function () {
    pinyin.englishPanel.hide()
    pinyin.pinyinPanel.hide()
    pinyin.numPanel.hide()
    pinyin.symbolPanel.hide()
    pinyin.container.hide()
    if (pinyin.callback) {
        pinyin.callback()
        pinyin.callback = null
    }
}
// Hidden callback, valid only once
pinyin.hideCb = function (cb) {
    pinyin.callback = cb
}
// Lock the keyboard to prevent switching modes.
pinyin.lock = function () {
    isLock = true
}
// Unlock keyboard
pinyin.unlock = function () {
    isLock = false
}
pinyin.pinyinSupport = function (bool) {
    enablePinyin = bool
}

// English keyboard
function createEnglish() {
    let englishPanel = dxui.View.build(pinyin.container.id + 'englishPanel', pinyin.container)
    clearStyle(englishPanel)
    englishPanel.setSize(pinyin.container.width(), pinyin.container.height())
    englishPanel.update()
    // Create a case-sensitive English keyboard
    function createKeyboard(capital) {
        let englishKeyboard = dxui.Buttons.build(englishPanel.id + 'englishKeyboard' + (capital ? "Big" : "Small"), englishPanel)
        clearStyle(englishKeyboard)
        englishKeyboard.obj.lvObjSetStylePadGap(10, dxui.Utils.ENUM._LV_STYLE_STATE_CMP_SAME)
        englishKeyboard.padAll(10)
        englishKeyboard.bgColor(0xffffff, dxui.Utils.STYLE_PART.ITEMS)
        englishKeyboard.bgColor(0xe6e6e6)
        englishKeyboard.setSize(englishPanel.width(), englishPanel.height())
        englishKeyboard.align(dxui.Utils.ALIGN.BOTTOM_MID, 0, 0)
        if (capital) {
            englishKeyboard.data([
                "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "\n",
                " ", "A", "S", "D", "F", "G", "H", "J", "K", "L", " ", "\n",
                "↓", "Z", "X", "C", "V", "B", "N", "M", " ", "\n",
                "!?#", "123", ",", " ", ".", "EN", " ",
                ""])
        } else {
            englishKeyboard.data([
                "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "\n",
                " ", "a", "s", "d", "f", "g", "h", "j", "k", "l", " ", "\n",
                "↑", "z", "x", "c", "v", "b", "n", "m", " ", "\n",
                "!?#", "123", ",", " ", ".", "EN", " ",
                ""])
        }
        // Set button width
        englishKeyboard.setBtnWidth(10, 1)
        for (let i = 11; i < 20; i++) {
            englishKeyboard.setBtnWidth(i, 2)
        }
        englishKeyboard.setBtnWidth(20, 1)
        englishKeyboard.setBtnWidth(21, 3)
        for (let i = 22; i < 29; i++) {
            englishKeyboard.setBtnWidth(i, 2)
        }
        englishKeyboard.setBtnWidth(29, 3)
        englishKeyboard.obj.addEventCb((e) => {
            let dsc = e.lvEventGetDrawPartDsc()
            if (dsc.class_p == englishKeyboard.obj.ClassP && dsc.type == dxui.Utils.ENUM.LV_BTNMATRIX_DRAW_PART_BTN) {
                // Hide useless buttons
                if (dsc.id == 10 || dsc.id == 20) {
                    dxui.Utils.GG.NativeDraw.lvDrawRectReset(dsc.rect_dsc, { bg_opa: 0, shadow_opa: 0 })
                }
                // Enhance the appearance of some function buttons
                if (dsc.id == 21 || dsc.id == 29 || dsc.id == 30 || dsc.id == 31 || dsc.id == 35) {
                    if (englishKeyboard.obj.lvBtnmatrixGetSelectedBtn() == dsc.id && e.lvEventGetTarget().hasState(dxui.Utils.ENUM.LV_STATE_PRESSED)) {
                        dxui.Utils.GG.NativeDraw.lvDrawRectReset(dsc.rect_dsc, { bg_color: 0xcdcdcd })
                    } else {
                        dxui.Utils.GG.NativeDraw.lvDrawRectReset(dsc.rect_dsc, { bg_color: 0xdbdbdb })
                    }
                }
                // The Enter button is blue.
                if (dsc.id == 36) {
                    if (englishKeyboard.obj.lvBtnmatrixGetSelectedBtn() == dsc.id && e.lvEventGetTarget().hasState(dxui.Utils.ENUM.LV_STATE_PRESSED)) {
                        dxui.Utils.GG.NativeDraw.lvDrawRectReset(dsc.rect_dsc, { bg_color: 0x0C6CE4 })
                    } else {
                        dxui.Utils.GG.NativeDraw.lvDrawRectReset(dsc.rect_dsc, { bg_color: 0x0C78FE })
                    }
                }
            }
        }, dxui.Utils.ENUM.LV_EVENT_DRAW_PART_BEGIN)
        englishKeyboard.obj.addEventCb((e) => {
            let dsc = e.lvEventGetDrawPartDsc()
            if (dsc.class_p == englishKeyboard.obj.ClassP && dsc.type == dxui.Utils.ENUM.LV_BTNMATRIX_DRAW_PART_BTN) {
                // Add a pattern to the delete button
                if (dsc.id == 29) {
                    let src = '/app/code/resource/image/backspace.png'
                    // Get image information
                    let header = dxui.Utils.GG.NativeDraw.lvImgDecoderGetInfo(src)
                    // Define a region and center it. Note: When converting a size to an area, subtract 1; when converting an area to a size, add 1.
                    let x1 = dsc.draw_area.x1 + (dsc.draw_area.x2 - dsc.draw_area.x1 + 1 - header.w) / 2;
                    let y1 = dsc.draw_area.y1 + (dsc.draw_area.y2 - dsc.draw_area.y1 + 1 - header.h) / 2;
                    let x2 = x1 + header.w - 1;
                    let y2 = y1 + header.h - 1;
                    let area = dxui.Utils.GG.NativeArea.lvAreaSet(x1, y1, x2, y2)
                    // Drawing image information
                    let img_draw_dsc = dxui.Utils.GG.NativeDraw.lvDrawImgDscInit()
                    // Drawing pictures
                    dxui.Utils.GG.NativeDraw.lvDrawImg(dsc.dsc, img_draw_dsc, area, src)
                }
                // Add Enter button icon
                if (dsc.id == 36) {
                    let src = '/app/code/resource/image/enter.png'
                    // Get image information
                    let header = dxui.Utils.GG.NativeDraw.lvImgDecoderGetInfo(src)
                    // Define a region and center it. Note: When converting a size to an area, subtract 1; when converting an area to a size, add 1.
                    let x1 = dsc.draw_area.x1 + (dsc.draw_area.x2 - dsc.draw_area.x1 + 1 - header.w) / 2;
                    let y1 = dsc.draw_area.y1 + (dsc.draw_area.y2 - dsc.draw_area.y1 + 1 - header.h) / 2;
                    let x2 = x1 + header.w - 1;
                    let y2 = y1 + header.h - 1;
                    let area = dxui.Utils.GG.NativeArea.lvAreaSet(x1, y1, x2, y2)
                    // Drawing image information
                    let img_draw_dsc = dxui.Utils.GG.NativeDraw.lvDrawImgDscInit()
                    // Drawing pictures
                    dxui.Utils.GG.NativeDraw.lvDrawImg(dsc.dsc, img_draw_dsc, area, src)
                }
                // Add pattern to space bar button
                if (dsc.id == 33) {
                    let src = '/app/code/resource/image/space.png'
                    // Get image information
                    let header = dxui.Utils.GG.NativeDraw.lvImgDecoderGetInfo(src)
                    // Define a region and center it. Note: When converting a size to an area, subtract 1; when converting an area to a size, add 1.
                    let x1 = dsc.draw_area.x1 + (dsc.draw_area.x2 - dsc.draw_area.x1 + 1 - header.w) / 2;
                    let y1 = dsc.draw_area.y1 + (dsc.draw_area.y2 - dsc.draw_area.y1 + 1 - header.h) / 2;
                    let x2 = x1 + header.w - 1;
                    let y2 = y1 + header.h - 1;
                    y1 += 10
                    y2 += 10
                    let area = dxui.Utils.GG.NativeArea.lvAreaSet(x1, y1, x2, y2)
                    // Drawing image information
                    let img_draw_dsc = dxui.Utils.GG.NativeDraw.lvDrawImgDscInit()
                    // Drawing pictures
                    dxui.Utils.GG.NativeDraw.lvDrawImg(dsc.dsc, img_draw_dsc, area, src)
                }
            }
        }, dxui.Utils.ENUM.LV_EVENT_DRAW_PART_END)
        englishKeyboard.on(dxui.Utils.ENUM.LV_EVENT_LONG_PRESSED_REPEAT, () => {
            let clickBtn = englishKeyboard.clickedButton()
            let id = clickBtn.id
            switch (id) {
                case 29:
                    // Backspace
                    pinyin.cb({ cmd: "backspace" })
                    break;
            }
        })
        englishKeyboard.on(dxui.Utils.ENUM.LV_EVENT_PRESSED, () => {
            let clickBtn = englishKeyboard.clickedButton()
            let id = clickBtn.id
            let text = clickBtn.text
            switch (id) {
                case 21:
                    // Case switching
                    if (englishKeyboardBig.isHide()) {
                        englishKeyboardBig.show()
                        englishKeyboardSmall.hide()
                    } else {
                        englishKeyboardBig.hide()
                        englishKeyboardSmall.show()
                    }
                    break;
                case 29:
                    // Backspace
                    pinyin.cb({ cmd: "backspace" })
                    break;
                case 30:
                    if (isLock) {
                        break;
                    }
                    // Switch symbol keyboard
                    pinyin.symbolPanel.show()
                    pinyin.englishPanel.hide()
                    break;
                case 31:
                    if (isLock) {
                        break;
                    }
                    // Switch numeric keypad
                    pinyin.numPanel.show()
                    pinyin.englishPanel.hide()
                    break;
                case 33:
                    // Space
                    pinyin.cb(" ")
                    break;
                case 35:
                    if (isLock || !enablePinyin) {
                        break;
                    }
                    // Switch to Pinyin keyboard
                    pinyin.pinyinPanel.show()
                    pinyin.englishPanel.hide()
                    break;
                case 36:
                    // Enter
                    pinyin.cb({ cmd: "enter" })
                    break;
                default:
                    break;
            }
            // Print characters
            if (["q", "w", "e", "r", "t", "y", "u", "i", "o", "p",
                "a", "s", "d", "f", "g", "h", "j", "k", "l",
                "z", "x", "c", "v", "b", "n", "m",
                ",", "."].includes(text) || [
                    "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P",
                    "A", "S", "D", "F", "G", "H", "J", "K", "L",
                    "Z", "X", "C", "V", "B", "N", "M",
                    ",", "."].includes(text)) {
                pinyin.cb(text)
            }
        })
        return englishKeyboard
    }
    // Create a Caps Lock keyboard
    let englishKeyboardBig = createKeyboard(true)
    let englishKeyboardSmall = createKeyboard(false)
    // The default is lowercase.
    englishKeyboardBig.hide()
    englishKeyboardSmall.show()
    englishPanel.hide()
    return englishPanel
}

// numeric keypad
function createNum() {
    let numPanel = dxui.View.build(pinyin.container.id + 'numPanel', pinyin.container)
    clearStyle(numPanel)
    numPanel.setSize(pinyin.container.width(), pinyin.container.height())
    numPanel.update()
    // Create a numeric keypad
    let numKeyboard = dxui.Buttons.build(numPanel.id + 'numKeyboard', numPanel)
    clearStyle(numKeyboard)
    numKeyboard.obj.lvObjSetStylePadGap(10, dxui.Utils.ENUM._LV_STYLE_STATE_CMP_SAME)
    numKeyboard.padAll(10)
    numKeyboard.bgColor(0xffffff, dxui.Utils.STYLE_PART.ITEMS)
    numKeyboard.bgColor(0xe6e6e6)
    numKeyboard.setSize(numPanel.width(), numPanel.height())
    numKeyboard.data([
        "1", "2", "3", " ", "\n",
        "4", "5", "6", "+", "\n",
        "7", "8", "9", "-", "\n",
        "ABC", "0", ".", " ", "",
    ])
    numKeyboard.obj.addEventCb((e) => {
        let dsc = e.lvEventGetDrawPartDsc()
        if (dsc.class_p == numKeyboard.obj.ClassP && dsc.type == dxui.Utils.ENUM.LV_BTNMATRIX_DRAW_PART_BTN) {
            // Enhance the two function buttons
            if ([3, 7, 11, 12, 14].includes(dsc.id)) {
                if (numKeyboard.obj.lvBtnmatrixGetSelectedBtn() == dsc.id && e.lvEventGetTarget().hasState(dxui.Utils.ENUM.LV_STATE_PRESSED)) {
                    dxui.Utils.GG.NativeDraw.lvDrawRectReset(dsc.rect_dsc, { bg_color: 0xcdcdcd })
                } else {
                    dxui.Utils.GG.NativeDraw.lvDrawRectReset(dsc.rect_dsc, { bg_color: 0xdbdbdb })
                }
            }
            // The Enter button is blue.
            if (dsc.id == 15) {
                if (numKeyboard.obj.lvBtnmatrixGetSelectedBtn() == dsc.id && e.lvEventGetTarget().hasState(dxui.Utils.ENUM.LV_STATE_PRESSED)) {
                    dxui.Utils.GG.NativeDraw.lvDrawRectReset(dsc.rect_dsc, { bg_color: 0x0C6CE4 })
                } else {
                    dxui.Utils.GG.NativeDraw.lvDrawRectReset(dsc.rect_dsc, { bg_color: 0x0C78FE })
                }
            }
        }
    }, dxui.Utils.ENUM.LV_EVENT_DRAW_PART_BEGIN)
    numKeyboard.obj.addEventCb((e) => {
        let dsc = e.lvEventGetDrawPartDsc()
        if (dsc.class_p == numKeyboard.obj.ClassP && dsc.type == dxui.Utils.ENUM.LV_BTNMATRIX_DRAW_PART_BTN) {
            // Delete button icon
            if (dsc.id == 3) {
                let src = '/app/code/resource/image/backspace.png'
                // Get image information
                let header = dxui.Utils.GG.NativeDraw.lvImgDecoderGetInfo(src)
                // Define a region and center it. Note: When converting a size to an area, subtract 1; when converting an area to a size, add 1.
                let x1 = dsc.draw_area.x1 + (dsc.draw_area.x2 - dsc.draw_area.x1 + 1 - header.w) / 2;
                let y1 = dsc.draw_area.y1 + (dsc.draw_area.y2 - dsc.draw_area.y1 + 1 - header.h) / 2;
                let x2 = x1 + header.w - 1;
                let y2 = y1 + header.h - 1;
                let area = dxui.Utils.GG.NativeArea.lvAreaSet(x1, y1, x2, y2)
                // Drawing image information
                let img_draw_dsc = dxui.Utils.GG.NativeDraw.lvDrawImgDscInit()
                // Drawing pictures
                dxui.Utils.GG.NativeDraw.lvDrawImg(dsc.dsc, img_draw_dsc, area, src)
            }
            if (dsc.id == 15) {
                let src = '/app/code/resource/image/enter.png'
                // Get image information
                let header = dxui.Utils.GG.NativeDraw.lvImgDecoderGetInfo(src)
                // Define a region and center it. Note: When converting a size to an area, subtract 1; when converting an area to a size, add 1.
                let x1 = dsc.draw_area.x1 + (dsc.draw_area.x2 - dsc.draw_area.x1 + 1 - header.w) / 2;
                let y1 = dsc.draw_area.y1 + (dsc.draw_area.y2 - dsc.draw_area.y1 + 1 - header.h) / 2;
                let x2 = x1 + header.w - 1;
                let y2 = y1 + header.h - 1;
                let area = dxui.Utils.GG.NativeArea.lvAreaSet(x1, y1, x2, y2)
                // Drawing image information
                let img_draw_dsc = dxui.Utils.GG.NativeDraw.lvDrawImgDscInit()
                // Drawing pictures
                dxui.Utils.GG.NativeDraw.lvDrawImg(dsc.dsc, img_draw_dsc, area, src)
            }
        }
    }, dxui.Utils.ENUM.LV_EVENT_DRAW_PART_END)
    numKeyboard.on(dxui.Utils.ENUM.LV_EVENT_LONG_PRESSED_REPEAT, () => {
        let clickBtn = numKeyboard.clickedButton()
        let id = clickBtn.id
        switch (id) {
            case 3:
                // Backspace
                pinyin.cb({ cmd: "backspace" })
                break;
        }
    })
    numKeyboard.on(dxui.Utils.ENUM.LV_EVENT_PRESSED, () => {
        let clickBtn = numKeyboard.clickedButton()
        let id = clickBtn.id
        let text = clickBtn.text
        switch (id) {
            case 3:
                // Backspace
                pinyin.cb({ cmd: "backspace" })
                break;
            case 12:
                if (isLock) {
                    break;
                }
                // Switch to English keyboard
                pinyin.englishPanel.show()
                pinyin.numPanel.hide()
                break;
            case 15:
                // Enter
                pinyin.cb({ cmd: "enter" })
                break;
            default:
                break;
        }
        // Print characters
        if (["1", "2", "3",
            "4", "5", "6", "+",
            "7", "8", "9", "-",
            "0", "."].includes(text)) {
            pinyin.cb(text)
        }
    })
    numPanel.hide()
    return numPanel
}

// Symbol keyboard
function createSymbol() {
    let symbolPanel = dxui.View.build(pinyin.container.id + 'symbolPanel', pinyin.container)
    clearStyle(symbolPanel)
    symbolPanel.setSize(pinyin.container.width(), pinyin.container.height())
    symbolPanel.update()
    // Create a symbol keyboard
    let symbolKeyboard = dxui.Buttons.build(symbolPanel.id + 'symbolKeyboard', symbolPanel)
    clearStyle(symbolKeyboard)
    symbolKeyboard.obj.lvObjSetStylePadGap(10, dxui.Utils.ENUM._LV_STYLE_STATE_CMP_SAME)
    symbolKeyboard.padAll(10)
    symbolKeyboard.bgColor(0xffffff, dxui.Utils.STYLE_PART.ITEMS)
    symbolKeyboard.bgColor(0xe6e6e6)
    symbolKeyboard.setSize(symbolPanel.width(), symbolPanel.height())
    symbolKeyboard.data([
        "^", "\\", "|", "<", ">", "¢", "£", "€", "¥", "₱", "\n",
        "[", "]", "{", "}", "#", "%", "+", "=", "~", "_", "\n",
        " ", "-", "/", ":", ";", "(", ")", "$", "&", "\"", " ", "\n",
        "123", "`", "?", "!", "*", "@", ",", "'", " ", "\n",
        "ABC", " ", " ", ""
    ])
    symbolKeyboard.setBtnWidth(20, 1)
    for (let i = 21; i < 30; i++) {
        symbolKeyboard.setBtnWidth(i, 2)
    }
    symbolKeyboard.setBtnWidth(30, 1)
    symbolKeyboard.setBtnWidth(31, 3)
    for (let i = 32; i < 39; i++) {
        symbolKeyboard.setBtnWidth(i, 2)
    }
    symbolKeyboard.setBtnWidth(39, 3)
    symbolKeyboard.setBtnWidth(41, 2)
    symbolKeyboard.obj.addEventCb((e) => {
        let dsc = e.lvEventGetDrawPartDsc()
        if (dsc.class_p == symbolKeyboard.obj.ClassP && dsc.type == dxui.Utils.ENUM.LV_BTNMATRIX_DRAW_PART_BTN) {
            // Hide useless buttons
            if (dsc.id == 20 || dsc.id == 30) {
                dxui.Utils.GG.NativeDraw.lvDrawRectReset(dsc.rect_dsc, { bg_opa: 0, shadow_opa: 0 })
            }
            // Enhance the appearance of some function buttons
            if (dsc.id == 31 || dsc.id == 39 || dsc.id == 40 || dsc.id == 41 || dsc.id == 45) {
                if (symbolKeyboard.obj.lvBtnmatrixGetSelectedBtn() == dsc.id && e.lvEventGetTarget().hasState(dxui.Utils.ENUM.LV_STATE_PRESSED)) {
                    dxui.Utils.GG.NativeDraw.lvDrawRectReset(dsc.rect_dsc, { bg_color: 0xcdcdcd })
                } else {
                    dxui.Utils.GG.NativeDraw.lvDrawRectReset(dsc.rect_dsc, { bg_color: 0xdbdbdb })
                }
            }
            // The Enter button is blue.
            if (dsc.id == 42) {
                if (symbolKeyboard.obj.lvBtnmatrixGetSelectedBtn() == dsc.id && e.lvEventGetTarget().hasState(dxui.Utils.ENUM.LV_STATE_PRESSED)) {
                    dxui.Utils.GG.NativeDraw.lvDrawRectReset(dsc.rect_dsc, { bg_color: 0x0C6CE4 })
                } else {
                    dxui.Utils.GG.NativeDraw.lvDrawRectReset(dsc.rect_dsc, { bg_color: 0x0C78FE })
                }
            }
        }
    }, dxui.Utils.ENUM.LV_EVENT_DRAW_PART_BEGIN)
    symbolKeyboard.obj.addEventCb((e) => {
        let dsc = e.lvEventGetDrawPartDsc()
        if (dsc.class_p == symbolKeyboard.obj.ClassP && dsc.type == dxui.Utils.ENUM.LV_BTNMATRIX_DRAW_PART_BTN) {
            if (dsc.id == 39) {
                let src = '/app/code/resource/image/backspace.png'
                // Get image information
                let header = dxui.Utils.GG.NativeDraw.lvImgDecoderGetInfo(src)
                // Define a region and center it. Note: When converting a size to an area, subtract 1; when converting an area to a size, add 1.
                let x1 = dsc.draw_area.x1 + (dsc.draw_area.x2 - dsc.draw_area.x1 + 1 - header.w) / 2;
                let y1 = dsc.draw_area.y1 + (dsc.draw_area.y2 - dsc.draw_area.y1 + 1 - header.h) / 2;
                let x2 = x1 + header.w - 1;
                let y2 = y1 + header.h - 1;
                let area = dxui.Utils.GG.NativeArea.lvAreaSet(x1, y1, x2, y2)
                // Drawing image information
                let img_draw_dsc = dxui.Utils.GG.NativeDraw.lvDrawImgDscInit()
                // Drawing pictures
                dxui.Utils.GG.NativeDraw.lvDrawImg(dsc.dsc, img_draw_dsc, area, src)
            }
            if (dsc.id == 42) {
                let src = '/app/code/resource/image/enter.png'
                // Get image information
                let header = dxui.Utils.GG.NativeDraw.lvImgDecoderGetInfo(src)
                // Define a region and center it. Note: When converting a size to an area, subtract 1; when converting an area to a size, add 1.
                let x1 = dsc.draw_area.x1 + (dsc.draw_area.x2 - dsc.draw_area.x1 + 1 - header.w) / 2;
                let y1 = dsc.draw_area.y1 + (dsc.draw_area.y2 - dsc.draw_area.y1 + 1 - header.h) / 2;
                let x2 = x1 + header.w - 1;
                let y2 = y1 + header.h - 1;
                let area = dxui.Utils.GG.NativeArea.lvAreaSet(x1, y1, x2, y2)
                // Drawing image information
                let img_draw_dsc = dxui.Utils.GG.NativeDraw.lvDrawImgDscInit()
                // Drawing pictures
                dxui.Utils.GG.NativeDraw.lvDrawImg(dsc.dsc, img_draw_dsc, area, src)
            }
            if (dsc.id == 41) {
                let src = '/app/code/resource/image/space.png'
                // Get image information
                let header = dxui.Utils.GG.NativeDraw.lvImgDecoderGetInfo(src)
                // Define a region and center it. Note: When converting a size to an area, subtract 1; when converting an area to a size, add 1.
                let x1 = dsc.draw_area.x1 + (dsc.draw_area.x2 - dsc.draw_area.x1 + 1 - header.w) / 2;
                let y1 = dsc.draw_area.y1 + (dsc.draw_area.y2 - dsc.draw_area.y1 + 1 - header.h) / 2;
                let x2 = x1 + header.w - 1;
                let y2 = y1 + header.h - 1;
                y1 += 10
                y2 += 10
                let area = dxui.Utils.GG.NativeArea.lvAreaSet(x1, y1, x2, y2)
                // Drawing image information
                let img_draw_dsc = dxui.Utils.GG.NativeDraw.lvDrawImgDscInit()
                // Drawing pictures
                dxui.Utils.GG.NativeDraw.lvDrawImg(dsc.dsc, img_draw_dsc, area, src)
            }
        }
    }, dxui.Utils.ENUM.LV_EVENT_DRAW_PART_END)
    symbolKeyboard.on(dxui.Utils.ENUM.LV_EVENT_LONG_PRESSED_REPEAT, () => {
        let clickBtn = symbolKeyboard.clickedButton()
        let id = clickBtn.id
        switch (id) {
            case 39:
                // Backspace
                pinyin.cb({ cmd: "backspace" })
                break;
        }
    })
    symbolKeyboard.on(dxui.Utils.ENUM.LV_EVENT_PRESSED, () => {
        let clickBtn = symbolKeyboard.clickedButton()
        let id = clickBtn.id
        let text = clickBtn.text
        switch (id) {
            case 31:
                if (isLock) {
                    break;
                }
                // Switch numeric keypad
                pinyin.numPanel.show()
                pinyin.symbolPanel.hide()
                break;
            case 39:
                // Backspace
                pinyin.cb({ cmd: "backspace" })
                break;
            case 40:
                if (isLock) {
                    break;
                }
                // Switch to English keyboard
                pinyin.englishPanel.show()
                pinyin.symbolPanel.hide()
                break;
            case 41:
                // Space
                pinyin.cb(" ")
                break;
            case 42:
                // Enter
                pinyin.cb({ cmd: "enter" })
                break;
            default:
                break;
        }
        // Print characters
        if (["^", "\\", "|", "<", ">", "¢", "£", "€", "¥", "₱",
            "[", "]", "{", "}", "#", "%", "+", "=", "~", "_",
            "-", "/", ":", ";", "(", ")", "$", "&", "\"",
            "`", "?", "!", "*", "@", ",", "'"].includes(text)) {
            pinyin.cb(text)
        }
    })
    symbolPanel.hide()
    return symbolPanel
}
// Clear Style
function clearStyle(obj) {
    obj.radius(0)
    obj.borderWidth(0)
    obj.padAll(0)
}
export default pinyin
